import allure
import jsonpath
import logging
from utils.send_request_utils import send_sql_request


def excractor_json(case , res ,all ):   #因为all时字典，属于可变数据类型，所以修改时实际也会修改
    if case["jsonExData"]:
        with allure.step("核心步骤4：json的提取"):
            for key, value in eval(case["jsonExData"]).items():
                value = jsonpath.jsonpath(res.json(), value)[0]
                all[key] = value
            logging.info(f"第4个: 将根据{case['jsonExData']}来提取数据，最终的all为{all}")


def excractor_jdbc(case , all ):
    if case["sqlExData"]:
        with allure.step("核心步骤4：jdbc的提取"):
            for key, value in eval(case["sqlExData"]).items():
                value = send_sql_request(value)
                all[key] = value
            logging.info(f"第4个: 将根据{case['sqlExData']}来提取数据，最终的all为{all}")